home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / Sessions / Traut / ZStrings / Source / Linux / LinuxZString.cpp next >
Encoding:
C/C++ Source or Header  |  2001-06-23  |  5.1 KB  |  190 lines

  1. /*==================================================================
  2.     File:        LinuxZString.h
  3.     
  4.     Contains:    Linux-specific parsing for ZStrings.
  5.                 Okay, not really linux specific, but maybe X specific.
  6.  
  7.     Written by:    Jeremy Alves
  8.     
  9.     Copyright:    2000-2001 Connectix Corporation
  10.     
  11.     This source has been placed into the public domain by
  12.     Connectix Corporation. You have the right to modify, 
  13.     distribute or use this code without any legal limitations
  14.     or finanicial/licensing requirements. Connectix is not 
  15.     liable for any problems that result from the use of this 
  16.     code.
  17.     
  18.     If you have comments, feedback, questions, or would like
  19.     to submit bug fixes or updates to this code, please email
  20.     opensource@connectix.com.
  21. ==================================================================*/
  22.  
  23.  
  24. #include "LinuxZString.h"
  25. #include "ZStringDictionary.h"
  26.  
  27. /*------------------------------------------------------------------
  28.     Initialize                                        [static]
  29.     
  30.     This static method instantiates the singleton classes
  31.     for tracking ZStrings.
  32. ------------------------------------------------------------------*/
  33.  
  34. void
  35. LinuxZString::Initialize()
  36. {
  37.     new ZStringDictionary;
  38.     new LinuxZStringParser;
  39. }
  40.  
  41.  
  42. /*------------------------------------------------------------------
  43.     TearDown                                        [static]
  44. ------------------------------------------------------------------*/
  45.  
  46. void
  47. LinuxZString::TearDown()
  48. {
  49.     delete &ZStringDictionary::GetZStringDictionary();
  50.     delete &ZStringParser::GetZStringParser();
  51. }
  52.  
  53.  
  54. /*------------------------------------------------------------------
  55.     GetNamedCString                                    [static]
  56. ------------------------------------------------------------------*/
  57.  
  58. const char *
  59. LinuxZString::GetNamedCString(
  60.     const char *        inNamedString)
  61. {
  62.     ZString        namedString;
  63.     
  64.     namedString.GetNamedString(inNamedString);
  65.     return (namedString.GetCString());
  66. }
  67.  
  68.  
  69. /*------------------------------------------------------------------
  70.     GetTagReplacement
  71.  
  72.     This function is probably all wrong,
  73.     at might depend on the codepage we're using.
  74. ------------------------------------------------------------------*/
  75.  
  76. Z_UInt16
  77. LinuxZStringParser::GetTagReplacement(
  78.     ZStringTagID                inTagID,
  79.     char *                        outReplacement)
  80. {
  81.     // By default, all tags are one character.
  82.     UInt16        tagSize = 1;
  83.     
  84.     if (outReplacement != NULL)
  85.     {
  86.         static const char    sTagReplacements[] = {
  87.             '\0',                // kTagIDInvalid
  88.             '\xc6',                // kZTag_AElig,
  89.             '\xc1',                // kZTag_Aacute,
  90.             '\xc2',                // kZTag_Acirc,
  91.             '\xc0',                // kZTag_Agrave,
  92.             '\xc5',                // kZTag_Aring,
  93.             '\xc3',                // kZTag_Atilde,
  94.             '\xc4',                // kZTag_Auml,
  95.             '\xc7',                // kZTag_Ccedil,
  96.             '\xc9',                // kZTag_Eacute,
  97.             '\xca',                // kZTag_Ecirc,
  98.             '\xc8',                // kZTag_Egrave,
  99.             '\xcb',                // kZTag_Euml,
  100.             '\xcd',                // kZTag_Iacute,
  101.             '\xce',                // kZTag_Icirc,
  102.             '\xcc',                // kZTag_Igrave,
  103.             '\xcf',                // kZTag_Iuml,
  104.             '\xd1',                // kZTag_Ntilde,
  105.             '\xd3',                // kZTag_Oacute,
  106.             '\xd4',                // kZTag_Ocirc,
  107.             '\xd2',                // kZTag_Ograve,
  108.             '\xd8',                // kZTag_Oslash,
  109.             '\xd5',                // kZTag_Otilde,
  110.             '\xd6',                // kZTag_Ouml,
  111.             '\xda',                // kZTag_Uacute,
  112.             '\xdb',                // kZTag_Ucirc,
  113.             '\xd9',                // kZTag_Ugrave,
  114.             '\xdc',                // kZTag_Uuml,
  115.             '\xe1',                // kZTag_aacute,
  116.             '\xe2',                // kZTag_acirc,
  117.             '\xe6',                // kZTag_aelig,
  118.             '\xe0',                // kZTag_agrave,
  119.             '\x26',                // kZTag_amp,
  120.             '\xe5',                // kZTag_aring,
  121.             '\xe3',                // kZTag_atilde,
  122.             '\xe4',                // kZTag_auml,
  123.             '\x27',                // kZTag_bdquo,
  124.             '\xb7',                // kZTag_bull,
  125.             '\xe7',                // kZTag_ccedil,
  126.             '\x9b',                // kZTag_cent,
  127.             '\xa9',                // kZTag_copy,
  128.             '\xe9',                // kZTag_eacute,
  129.             '\xea',                // kZTag_ecirc,
  130.             '\xe8',                // kZTag_egrave,
  131.             '\xeb',                // kZTag_euml,
  132.             '\x3E',                // kZTag_gt,
  133.             '\x85',                // kZTag_hellip,
  134.             '\xed',                // kZTag_iacute,
  135.             '\xee',                // kZTag_icirc,
  136.             '\xa1',                // kZTag_iexcl,
  137.             '\xed',                // kZTag_igrave,
  138.             '\xbf',                // kZTag_iquest,
  139.             '\xef',                // kZTag_iuml,
  140.             '\x93',                // kZTag_ldquo,
  141.             '\x91',                // kZTag_lsquo,
  142.             '\x3C',                // kZTag_lt,
  143.             '\x2d',                // kZTag_mdash,
  144.             '\xb5',                // kZTag_micro,
  145.             //FIX ME
  146.             //'\~',                // kZTag_nbsp,
  147.             '\x20',                // kZTag_ndash,
  148.             '\xf1',                // kZTag_ntilde,
  149.             '\xf3',                // kZTag_oacute,
  150.             '\xf4',                // kZTag_ocirc,
  151.             '\xf2',                // kZTag_ograve,
  152.             '\xf8',                // kZTag_oslash,
  153.             '\xf5',                // kZTag_otilde,
  154.             '\xf6',                // kZTag_ouml,
  155.             '\x14',                // kZTag_para,
  156.             '\xe3',                // kZTag_pi,
  157.             '\x23',                // kZTag_pound,
  158.             '\x94',                // kZTag_rdquo,
  159.             '\x99',                // kZTag_reg,
  160.             '\x00',                // kZTag_replace
  161.             '\x92',                // kZTag_rsquo,
  162.             '\x82',                // kZTag_sbquo,
  163.             '\xdf',                // kZTag_szlig,
  164.             '\xae',                // kZTag_trade,
  165.             '\xfa',                // kZTag_uacute,
  166.             '\xfb',                // kZTag_ucirc,
  167.             '\xf9',                // kZTag_ugrave,
  168.             '\xfc',                // kZTag_uuml,
  169.             '\x9d',                // kZTag_yen,
  170.             '\xff',                // kZTag_yuml
  171.             '\x0d'                 // kZTag_br
  172.         };
  173.  
  174.         check(inTagID > kZTag_Invalid && inTagID < sizeof(sTagReplacements)/sizeof(char));
  175.         check(inTagID != kZTag_replace);
  176.  
  177.         // fill in the equivalent    
  178.         *outReplacement = sTagReplacements[inTagID];
  179.         if (inTagID == kZTag_hellip)
  180.             strcpy(outReplacement, "...");
  181.     }
  182.  
  183.     if (inTagID == kZTag_hellip)
  184.         tagSize = strlen("...");
  185.  
  186.     return tagSize;
  187. }
  188.  
  189.  
  190.